package com.ruoyi.partbase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.partbase.domain.PartBase;
import com.ruoyi.partbase.service.IPartBaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 建党基地Controller
 * 
 * @author ruoyi
 * @date 2023-09-26
 */
@RestController
@RequestMapping("/partbase/partbase")
public class PartBaseController extends BaseController
{
    @Autowired
    private IPartBaseService partBaseService;

    /**
     * 查询建党基地列表
     */
    @PreAuthorize("@ss.hasPermi('partbase:partbase:list')")
    @GetMapping("/list")
    public TableDataInfo list(PartBase partBase)
    {
        startPage();
        List<PartBase> list = partBaseService.selectPartBaseList(partBase);
        return getDataTable(list);
    }

    /**
     * 导出建党基地列表
     */
    @PreAuthorize("@ss.hasPermi('partbase:partbase:export')")
    @Log(title = "建党基地", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartBase partBase)
    {
        List<PartBase> list = partBaseService.selectPartBaseList(partBase);
        ExcelUtil<PartBase> util = new ExcelUtil<PartBase>(PartBase.class);
        util.exportExcel(response, list, "建党基地数据");
    }

    /**
     * 获取建党基地详细信息
     */
    @PreAuthorize("@ss.hasPermi('partbase:partbase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(partBaseService.selectPartBaseById(id));
    }

    /**
     * 新增建党基地
     */
    @PreAuthorize("@ss.hasPermi('partbase:partbase:add')")
    @Log(title = "建党基地", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartBase partBase)
    {
        return toAjax(partBaseService.insertPartBase(partBase));
    }

    /**
     * 修改建党基地
     */
    @PreAuthorize("@ss.hasPermi('partbase:partbase:edit')")
    @Log(title = "建党基地", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartBase partBase)
    {
        return toAjax(partBaseService.updatePartBase(partBase));
    }

    /**
     * 删除建党基地
     */
    @PreAuthorize("@ss.hasPermi('partbase:partbase:remove')")
    @Log(title = "建党基地", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(partBaseService.deletePartBaseByIds(ids));
    }
}
